import datetime
import os

from selenium import webdriver
from selenium.webdriver.common.by import By
import logging
# logging python自带的日志模块
# driver = webdriver.Chrome()
#
# driver.get("http://www.baidu.com")
# # get_screenshot_as_file 截图并保存到指定路径下
# # driver.get_screenshot_as_file(r'C:\Users\Administrator\Desktop\baidu.png')
#
# input_loc = (By.ID, "kw1")
# driver.find_element(*input_loc).send_keys('mmvk')



# logging.info("info")  # 消息
# logging.debug("debug")  # 调试信息
# logging.warning("warning")  # 警告
# logging.error("error")    # 错误
# logging.critical("critical")  # 严重

def get_log(msg,level):
    logger = logging.getLogger()
    logger.setLevel('DEBUG')
    formatter = logging.Formatter('%(asctime)s-%(levelname)s-%(filename)s-%(name)s-日志信息:%(message)s')

    ch = logging.StreamHandler()
    ch.setLevel('DEBUG')
    ch.setFormatter(formatter)

    fh = logging.FileHandler(filename='./test_results/logs/test_log.txt', encoding='utf-8')
    fh.setLevel('DEBUG')
    fh.setFormatter(formatter)

    logger.addHandler(ch)
    logger.addHandler(fh)

    if level == "DEBUG":
        logger.debug(msg)
    elif level == 'WARNING':
        logger.info(msg)

    logger.removeHandler(fh)
    logger.removeHandler(ch)

print(os.path.abspath('./test_results/logs/test_log.txt'))
get_log('dddddd','DEBUG')
get_log('wwwwww','WARNING')

